package com.frxuexi.document

import com.frxuexi.lib_base.ApiResponse
import com.frxuexi.lib_base.BaseViewModel
import com.frxuexi.lib_base.HttpType
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class DocViewModel @Inject constructor(private val docRepository: DocRepository):BaseViewModel<DocIntent>() {
    override fun handleIntent(it: DocIntent) {
        when(it){
            is DocIntent.getDocs->{
                httpRequest(docRepository.getDocs(it.map) as Flow<ApiResponse<Any>>)
            }
            is DocIntent.scanFile->{
                scanFile(it.file)
            }
            is DocIntent.deleteDoc->{
                httpRequest(docRepository.deleteDoc(it.map) as Flow<ApiResponse<Any>>,HttpType.DELETE)
            }
            is DocIntent.uploadDoc->{
                httpRequest(docRepository.uploadDoc(it.name,it.path) as Flow<ApiResponse<Any>>,HttpType.UPLOAD)
            }
        }
    }
}